package com.design;

import java.util.StringTokenizer;

import javax.swing.JTextField;

public class Validation {

	public StringTokenizer stringTokenizer;

	public boolean IsDigit(String text) {
		int index = 0;
		boolean status = true;
		char[] charText = text.toCharArray();
		while (charText.length > index) {
			if ((int) charText[index] < 48 || (int) charText[index] > 57) {
				status = false;
				break;
			}
			index++;
		}
		return status;
	}

	public boolean IsAmountt(String text) {
		int index = 0;
		boolean status = true;
		char[] charText = text.toCharArray();
		while (charText.length > index) {
			if ((int) charText[index] != 46
					&& ((int) charText[index] < 48 || (int) charText[index] > 57)) {
				status = false;
				break;
			}
			index++;
		}
		return status;
	}
public boolean isEmail(String text)
{
	int index = 0;
	boolean status = true;
	char[] charText = text.toCharArray();
	while (charText.length > index) {
		if ((int) charText[index] != 46
				&& ((int) charText[index] >= 33 && (int) charText[index] <= 47)) {
			status = false;
			break;
		}
		index++;
	}
	return status;
	
}
	public boolean IsName(String text) {
		int index = 0;
		boolean status = true;
		char[] charText = text.toCharArray();
		while (charText.length > index) {
			if ((int) charText[index] >= 33 && (int) charText[index] <= 47) {
				status = false;
				break;
			}
			index++;
		}
		return status;
	}

	public String RequestText(String jTextRequest) {
		String stringJtextRequest = new String();
		if (jTextRequest.equals("") || jTextRequest == null) {
			stringJtextRequest = "Enter the Request";
		}
		return stringJtextRequest;
	}

	public String accountNoTextField(String AccountNoTextField) {
		String stringAccountNoTextField = new String();
		boolean isDigit = IsDigit(AccountNoTextField);
		// System.out.println(AccountNoTextField.length());
		if (AccountNoTextField.equals("") || AccountNoTextField == null) {
			stringAccountNoTextField = "Enter the Account Number";
		} else if (!isDigit) {
			stringAccountNoTextField = "Invalid account number";
		} else if (AccountNoTextField.length() != 5) {
			stringAccountNoTextField = "Account field  is 5 digit";
		}
		return stringAccountNoTextField;
	}
	
	public String chequeNoTextField(String chequeNoTextField) {
		String stringchequeNoTextField = new String();
		boolean isDigit = IsDigit(chequeNoTextField);
		// System.out.println(AccountNoTextField.length());
		if (chequeNoTextField.equals("") || chequeNoTextField == null) {
			stringchequeNoTextField = "Enter the cheque Number";
		} else if (!isDigit) {
			stringchequeNoTextField = "Invalid cheque number";
		} else if (chequeNoTextField.length() != 5) {
			stringchequeNoTextField = "cheque field  is 5 digit";
		}
		return stringchequeNoTextField;
	}

	public String amountTextField(String amountText) {
		String stringAmountTextField = new String();
		String rupees = new String();
		String paise = new String();
		int index = 0;
		boolean length = false;
		boolean dotCheck = true;
		boolean dotCheck1 = true;
		if (amountText.length() > 0) {
			char[] toChar = amountText.toCharArray();

			while (toChar.length > index) {
				System.out.println(toChar[index]);
				if (toChar[index] == '.' && dotCheck == true) {
					dotCheck = true;
				} else if (toChar[index] == '.' && !dotCheck) {
					dotCheck1 = false;
					break;
				}
				++index;
			}
		}

		boolean isAmount = IsAmountt(amountText);
		System.out.println(amountText.contains("."));
		System.out.println(dotCheck);
		if (amountText.contains(".") && dotCheck1 && isAmount) {
			stringTokenizer = new StringTokenizer(amountText, ".");
			while (stringTokenizer.hasMoreTokens()) {
				rupees = stringTokenizer.nextToken();
				paise = stringTokenizer.nextToken();
			}

		} else {
			System.out.println("hrlloo");
			length = amountText.length() >= 6;
		}
		if (amountText.equals("") || amountText == null) {
			stringAmountTextField = "Enter amount feild";
		} else if (!dotCheck1) {
			stringAmountTextField = "Invalid rupees and paise field";
		} else if (!isAmount) {
			stringAmountTextField = "Invalid value";
		} else if (rupees.length() >= 6 || length) {
			System.out.println(rupees.length());
			System.out.println("jjj" + amountText.length());

			stringAmountTextField = "Incorrect rupees field";
		} else if (paise.length() != 0 && paise.length() != 2) {
			stringAmountTextField = "Incorrect paise field";
		}

		return stringAmountTextField;
	}

	public String NameValidationTextField(String name) {
		String stringNameTextField = new String();
		if (name.equals("") || name == null) {
			stringNameTextField = "Enter Name feild";
		}
		if (!IsName(name)) {
			stringNameTextField = "Special characters Not Allowed";
		}
		return stringNameTextField;
	}

	public String MobileNoTextField(String number) {
		String stringMobileTextField = new String();
		if (number.equals("")) {
			stringMobileTextField = "Enter the Mobile Number";
		} else if (number.length() != 10) {
			stringMobileTextField = "Invalid length";
		} else if (!IsDigit(number)) {
			stringMobileTextField = "Invalid Mobile Number";
		}
		return stringMobileTextField;
	}

	public String DateTextField(String date) {
		String stringDateTextField = new String();
		if (date.equals("") || date == null) {
			stringDateTextField = "Select the Date";
		}

		return stringDateTextField;
	}
	public String emailAddress(String emailAddress)
	{
		boolean isEmail=true;
		String result= new String();
		isEmail=isEmail(emailAddress);
		if(emailAddress.equals(""))
		{
			result="Enter the Email field";
		}
		else if(!emailAddress.contains("@")&&!emailAddress.contains(".")&&isEmail)
		{
			System.out.println(!emailAddress.contains("@"));
			System.out.println(!emailAddress.contains("."));
			System.out.println(isEmail);
			result="Invalid EmailAddress";
		}
		return result;
	}
	public static void main(String args[]) {
		Validation validation = new Validation();
		String value = validation.DateTextField("");
		// Boolean value=validation.IsAmountt("787@69");
		System.out.println(value);

	}
}
